﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mandy.Config.Model
{
    public class TResult<T>
    {
        public bool IsSuccess { get; set; } = true;
        public string Message { get; set; } = "";
        public int Code { get; set; } = TResultCode.SUCCESS;
        public T Body { get; set; }

        public TResult()
        {

        }

        public static TResult<T> BuildResult(T Body, string Message = "操作成功", bool IsSuccess = true)
        {
            TResult<T> Result = new TResult<T>();

            Result.Body = Body;

            Result.Message = Message;

            Result.IsSuccess = IsSuccess;

            return Result;
        }

        public void SetSuccess(string Message = "操作成功", int Code = TResultCode.SUCCESS)
        {
            this.Message = Message;
            this.IsSuccess = true;
            this.Code = TResultCode.SUCCESS;
        }
        public void SetFail(string Message = "操作失败", int Code = TResultCode.FAIL)
        {
            this.Message = Message;
            this.IsSuccess = false;
            this.Code = Code;
        }
    }
}
